package com.example.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.springboot.common.PageParam;
import com.example.springboot.common.Result;
import com.example.springboot.entity.AgePopulation;
import com.example.springboot.service.AgePopulationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description
 * @Author 
 * @Date 2025/4/20
 */
@RestController
@RequestMapping("/agePopulation")
public class AgePopulationController {

    @Resource
    private AgePopulationService agePopulationService;

    @PostMapping("api/save")
    public Result save(@RequestBody AgePopulation agePopulation){
        agePopulationService.saveOrUpdate(agePopulation);
        return Result.success(agePopulation);
    }
    @PostMapping("api/del/{id}")
    public Result del(@PathVariable Integer id){
        agePopulationService.removeById(id);
        return Result.success();
    }
    @GetMapping("page")
    public Result page(PageParam<AgePopulation> pageParam, AgePopulation agePopulation){
        LambdaQueryWrapper<AgePopulation> wrapper = Wrappers.lambdaQuery(agePopulation);
        PageParam<AgePopulation> page = agePopulationService.page(pageParam, wrapper);
        return Result.success(page);
    }

    @PostMapping("/getMaleList")
    public Result getMaleList() {
        return Result.success(agePopulationService.getMaleList());
    }

    @PostMapping("/getFemaleList")
    public Result getFemaleList() {
        return Result.success(agePopulationService.getFemaleList());
    }
}
